package com.meiyou.controller;

import com.meiyou.dto.RecordMenstruationDto;
import com.meiyou.result.Result;
import com.meiyou.service.MenstrualRecordService;
import com.meiyou.vo.MenstruationVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @BelongsProject: meiyou
 * @BelongsPackage: com.meiyou.controller
 * @Author: 尹晓安
 * @Date: 2023/12/4 21:46
 * @Description:
 */
@RestController
@RequestMapping("/api/menstrualRecord")
@Slf4j
public class MenstrualRecordController {

    @Autowired
    MenstrualRecordService menstrualRecordService;

    /**
     * 记录月经
     *
     * @param recordMenstruationDto
     * @return
     */
    @PostMapping
    public Result recordMenstruation(@RequestBody RecordMenstruationDto recordMenstruationDto) {

        menstrualRecordService.recordMenstruation(recordMenstruationDto);

        return Result.success("记录成功！");
    }

    /**
     * 获取月经信息
     *
     * @return
     */
    @GetMapping
    public Result<List<MenstruationVo>> getMenstruation() {

        List<MenstruationVo> menstruationVoList = menstrualRecordService.getMenstruation();

        return Result.success(menstruationVoList);
    }

    /**
     * 查询最新月经结束日期
     *
     * @return
     */
    @GetMapping("/queryEndLast")
    public Result<Map> queryMenstrualEndLast() {

        String endTime = menstrualRecordService.queryMenstrualEndLast();

        Map map = new HashMap<>();
        map.put("endTime", endTime);

        return Result.success(map);
    }

    /**
     * 查询最新的月经数据
     *
     * @return
     */
    @GetMapping("/queryLast")
    public Result<MenstruationVo> queryMenstrualLast() {

        MenstruationVo menstruationVo = menstrualRecordService.queryMenstrualLast();

        return Result.success(menstruationVo);
    }

}
